using System;
using System.Collections.Generic;
using UnityEngine;

namespace IQIGame.Onigao.Game
{
    internal class FixTimeCounter : Counter
    {

        protected override void AddCount(float deltaTime, float unscaledDeltaTime)
        {
            _Counter += unscaledDeltaTime;
        }


        public override void OnUpdate(float deltaTime, float unscaledDeltaTime)
        {
            if (Expired)
            {
                return;
            }

            AddCount(deltaTime, unscaledDeltaTime);

            while (_Counter >= Interval)
            {
                if (Loop < 0)
                {
                    _Counter -= Interval;
                    CallComplete();
                }
                else
                {
                    Loop--;
                    if (Loop <= 0)
                    {
                        Expired = true;
                        CallComplete();
                        break;
                    }
                    else
                    {
                        _Counter -= Interval;
                        CallComplete();
                    }
                }
            }
        }


    }
}
